<?php

// 9/18/2009: immanuel192 write this action

// this action show your all current orders which not finished

if (!defined("EXPONENT")) exit("");
if (!exponent_sessions_loggedIn())
{
	// redirect to homepage
	echo "<script language=javascript>document.location='".URL_BASE."/index.php';</script>";
	die();
}
  // 10/10/2009: immanuel192 write page split function
  // get orders here
  $count_post = $db->countObjects('orders');
		
  // page split
  // cal how many posts
  $max_item=25;
  $page_count=floor($count_post / $max_item);
  if ($count_post % $max_item != 0)
	 $page_count++;
		
  // get page
  $page=1;
  if (isset($_REQUEST['page']))  $page=intval($_REQUEST['page']);
  if (($page<1) || ($page>$page_count)) $page=1;
  $start_pos=($page-1)*$max_item;
		
  global $user;
  global $db;
$template = new template('storemodule','_current_order',$loc);
  exponent_flow_set(SYS_FLOW_PUBLIC);	
  // get all order in history (which is state = 0)
  $ticket=exponent_sessions_getTicketString();
  $get_lang=exponent_lang_loadFile("modules/storemodule/step.php");
  $sql="SELECT {$db->prefix}orders.* FROM {$db->prefix}orders 	ORDER BY  add_date DESC LIMIT {$start_pos},{$max_item}";
  $order=$db->selectObjectsBySql($sql);
  foreach ($order as $key=>$value){
	$value->add_date=date($get_lang['date_format'],$value->add_date);
	// for state
	if ($value->state == 2)
		$value->state=$get_lang['state_waiting'];
	elseif ($value->state == 1)
		$value->state=$get_lang['state_sending'];
	else $value->state=$get_lang['state_finish'];
  }
  $perms = storemodule::permissions();
  $template->register_permissions(array_keys($perms),$loc);
  $template->assign("orders",$order);
  $template->assign('pages',$page_count);
  $template->assign('start_post',$start_pos);
  $template->assign('page',$page);
  $template->output();
?>
